<?php
namespace app\ausagent\controller;
use think\Request;
use think\Db;
use think\Session;
use think\Cookie;
use think\Controller;
use think\Config;
use Godok\Org\Auth;

class Common extends Controller
{
	public function _initialize(){
		if(!session('id')){
          // $this->error('您尚未登录系统',url('login/index')); 
        $this->redirect(\think\Request::instance()->root().'/ausagent/Login/index');
    }
    //查询运营商（代理商）订单到期时间
    $isDq = Db::name('operator_order')->where('oid',session('oid'))->order('create_time desc')->find();
    if($isDq){
        $expirationTime = $isDq['old_expiration_date'] - time();
        $expirationTime = (floor($expirationTime/(3600*24)));
        //如果已过期跳转到续费页面
        if($expirationTime<0){
            $this->redirect(\think\Request::instance()->root().'/ausagent/Renew/index');
        }
        $this->assign('expirationTime',$expirationTime);
    }

        $csh = Db::name('operator')->where('id',session('oid'))->find();
        if($csh['initialization']==0){//判断是否进行了初始化,0表示没有,1表示已经进行过初始化了
        	//return $this->fetch('initialization/index');
        	$this->redirect(\think\Request::instance()->root().'/ausagent/Initialization/index');
        }
        //var_dump($ret);die;

	}

    public function lang() {
        switch ($_GET['lang']) {
            case 'cn':
                cookie('think_var', 'zh-cn');
                break;
            case 'en':
                cookie('think_var', 'en-us');
                break;
            //其它语言
        }
    }
}	



